package com.cloud.controller;

import cn.hutool.core.util.StrUtil;
import com.cloud.common.response.ProException;
import com.cloud.pojo.Payment;
import com.cloud.service.IPaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Slf4j
@RequestMapping(value = "/payment")
public class PaymentController {

    @Resource
    private IPaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;

    @Value("${spring.application.name}")
    private String serverName;

    @GetMapping(value = "/queryById")
    public Payment queryById(@RequestParam("id") String id){
        if(StrUtil.isBlank(id)){
            throw new ProException("参数异常");
        }
        Payment payment = paymentService.queryById(id);
        return payment;
    }

    @PostMapping(value = "/savePayment")
    public void savePayment(){
        Payment payment = new Payment();
        payment.setId("1234456");
        payment.setSerial("kshfjdsf");
        paymentService.savePayment(payment);
    }

    @GetMapping(value = "/getServerPort/{id}")
    public String getServerPort(@PathVariable("id") Integer id){
        return serverName + ", serverPort: " + serverPort + ", id: " + id;
    }
}
